package cn.ecut.dzy.juc;

import java.util.concurrent.CountDownLatch;

/**
 * @program: juc
 * @description:
 * @author: DingZhenYun
 * @create: 2021-10-19 14:06
 **/

public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        //6个同学陆续离开教室之后，班长锁门
        CountDownLatch countDownLatch=new CountDownLatch(6);
        //6个同学陆续离开教室之后

        for (int i=0;i<6;i++){
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+" 号同学离开了教室");
                countDownLatch.countDown();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            },String.valueOf(i)).start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName()+" 班长锁门走人了");

    }
}
